from sanic.response import json
from sanic import Blueprint
from playhouse.shortcuts import model_to_dict
from model.model import TUser

rt = Blueprint("user",url_prefix="user")

# list
@rt.get("/")
def indexHandle(req):
    rows = TUser().select()
    res = []
    for m in rows:
        dic = model_to_dict(m)
        del dic["upasswd"]
        res.append(dic)
    return json({
            "msg":"this is book",
            "code":0,
            "data":res
    })


@rt.get("/<id>")
def handle(req,id):
    m = TUser(uid=id).get()
    res = model_to_dict(m)
    return json({
            "msg":"ok2",
            "code":0,
            "data":res
    })